package com.boarsoft.soagov.route;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.boarsoft.common.util.RandomUtil;

public class SimpleRouterImpl implements ServiceRouter {
	/** { providerVersion: { serverAddress: weight } } */
	protected Map<String, Map<String, Integer>> targetMap = new ConcurrentHashMap<String, Map<String, Integer>>();
	/** { consumerVersion: providerVersion } */
	protected Map<String, String> versionMap = new ConcurrentHashMap<String, String>();

	@Override
	public String getProvider(Object req) {
		// TODO 从req中取出服务请求（消息者）版本号
		String cv = null;
		String pv = versionMap.get(cv);
		Map<String, Integer> m = targetMap.get(pv);
		return RandomUtil.random(m);
	}

	@Override
	public void config() {
		// TODO 从配置文件加载路由配置
	}
}